<template>
  <div class="container-fluid">
    <ul class="list-group">
      <li
        v-for="(v, i) in tableData"
        :key="`1worker${i}`"
        class="list-group-item d-flex justify-content-between align-items-center"
      >
        <router-link :to="{name: '查看下课点评', params: { ID: v.ID }}">
          <svg class="icon svg-icon" aria-hidden="true">
            <use xlink:href="#iconweidu" />
          </svg>
          今天有您的课程: {{v.info}}
        </router-link>
      </li>
    </ul>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import { sortBy } from "underscore";
import { totime } from "../../../utils.js";
export default {
  name: "worker",
  data() {
    return {
      currentPage: 1,
      pagesize: 10,
      time: new Date().toLocaleDateString()
    };
  },
  props: ["getschoolclazzschedule"],
  computed: {
    ...mapGetters([
      "getschoolclazz",
      "getschooluser",
      "getschoolclassroom",
      "getuser"
    ]),
    total() {
      const d = new Date(this.time).toLocaleDateString();
      return this.getschoolclazzschedule.filter(v => {
        return (
          new Date(v.starttime).toLocaleDateString() == d &&
          [v.schooluserid, v.schooluserids].includes(this.getuser.ID)
        );
      });
    },
    tableData() {
      const { total, currentPage, pagesize } = this;
      const x = total;
      let arr = [];
      for (let v in x) {
        if (
          v < currentPage * pagesize &&
          v > (currentPage - 1) * pagesize - 1
        ) {
          arr.push(x[v]);
        }
      }
      return sortBy(arr, v => {
        const a1 = v.schoolclasstime.split(":")[0];
        return Number(a1);
      });
    }
  },
  methods: {
    totime,
    gettime(row) {
      const { starttime, endtime } = row;
      return `${starttime}-${endtime}`;
    },
    usernameids(id) {
      if (id) {
        const data = this.getschooluser.find(v => v.ID == id);
        return data ? data.name : "";
      }
      return "";
    }
  }
};
</script>

<style lang="scss" scoped>
.index-model {
  margin-top: 13px;
}
.list-group-item {
  border-color: #ffffff;
}
</style>